/* freeircd alloc.c
 *
 * Iniciado em 09/05/2007 (restuturado de outros ficheiros)
 */
 
#if 0
#include <stdlib.h>
#include <types.h>

#include "debug.h"

extern inline void memerror(void *);

/* Nota: As funções neste ficheiro devem assegurar apenas as ligações das listas.
 *       So' aos membros next e prev devem ser atribuidos valores
 *
 * *NUNCA* devera' ser feito nenhum free()
 */

CLIENTS *alloc_client(CLIENTS **plst)
{
        CLIENTS *cl;

        if (*plst == NULL)
        {
                cl=*plst=malloc(sizeof(**plst));
                memerror(cl);
                cl->prev=NULL;
        }
        else
        {
                cl=*plst;

                while (cl != NULL)
                {
                        if (cl->next == NULL)
                                break;

                        cl=cl->next;
                }

                cl->next=malloc(sizeof(*cl->next));
                memerror(cl->next);

                cl->next->prev=cl;

                cl=cl->next;
        }

        cl->next=NULL;

        return cl;
}

void rm_client(CLIENTS **plst, CLIENTS *torm)
{
        if (torm->prev == NULL)
        {
                *plst=torm->next;
                if (torm->next != NULL)
                        torm->next->prev=NULL;
        }
        else
        {
                torm->prev->next=torm->next;

                if (torm->next != NULL)
                        torm->next->prev=torm->prev;
        }
}

struct user_chans_list *alloc_channel_in_user_list(struct user_chans_list **plst)
{
        struct user_chans_list *u_chs;

        if (*plst == NULL)
        {
                u_chs=*plst=malloc(sizeof(**plst));
                memerror(u_chs);
                u_chs->prev=NULL;
        }
        else
        {
                u_chs=*plst;

                while (u_chs != NULL)
                {
                        if (u_chs->next == NULL)
                                break;

                        u_chs=u_chs->next;
                }

                u_chs->next=malloc(sizeof(*u_chs->next));
                memerror(u_chs->next);

                u_chs->next->prev=u_chs;

                u_chs=u_chs->next;
        }

        u_chs->next=NULL;

        return u_chs;
}

void rm_channel_in_user_list(struct user_chans_list **plst, struct user_chans_list *torm)
{
        if (torm->prev == NULL)
        {
                *plst=torm->next;
                if (torm->next != NULL)
                        torm->next->prev=NULL;
        }
        else
        {
                torm->prev->next=torm->next;

                if (torm->next != NULL)
                        torm->next->prev=torm->prev;
        }
}

CHANS *alloc_channel(CHANS **plst)
{
        CHANS *chan;

        if (*plst == NULL)
        {
                chan=*plst=malloc(sizeof(**plst));
                memerror(chan);
                chan->prev=NULL;
        }
        else
        {
                chan=*plst;

                while (chan != NULL)
                {
                        if (chan->next == NULL)
                                break;

                        chan=chan->next;
                }

                chan->next=malloc(sizeof(*chan->next));
                memerror(chan->next);

                chan->next->prev=chan;

                chan=chan->next;
        }

        chan->next=NULL;

        return chan;
}

void rm_channel(CHANS **plst, CHANS *torm)
{
        if (torm->prev == NULL)
        {
                *plst=torm->next;
                if (torm->next != NULL)
                        torm->next->prev=NULL;
        }
        else
        {
                torm->prev->next=torm->next;

                if (torm->next != NULL)
                        torm->next->prev=torm->prev;
        }
}
#endif
